//
// DotNetNuke - http://www.dotnetnuke.com
// Copyright (c) 2002-2010
// by Perpetual Motion Interactive Systems Inc. ( http://www.perpetualmotion.ca )
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
// documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
// the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
// to permit persons to whom the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or substantial portions 
// of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
// TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
// CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
// DEALINGS IN THE SOFTWARE.
//

using System;
using DotNetNuke.Common.Utilities;
using DotNetNuke.Entities.Modules.Actions;
using DotNetNuke.Security;
namespace DotNetNuke.Modules.Admin.Vendors
{
	partial class Banners : Entities.Modules.PortalModuleBase, Entities.Modules.IActionable
	{
		public int VendorID;
		private void BindData()
		{
			Services.Vendors.BannerController objBanners = new Services.Vendors.BannerController();
			Services.Localization.Localization.LocalizeDataGrid(ref grdBanners, this.LocalResourceFile);
			grdBanners.DataSource = objBanners.GetBanners(VendorID);
			grdBanners.DataBind();
			cmdAdd.NavigateUrl = FormatURL("BannerId", "-1");
		}
		public string DisplayDate(System.DateTime DateValue)
		{
			string _DisplayDate = Null.NullString;
			try {
				if (Null.IsNull(DateValue)) {
					_DisplayDate = "";
				} else {
					_DisplayDate = DateValue.ToShortDateString();
				}
			} catch (Exception exc) {
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
			return _DisplayDate;
		}
		public string DisplayType(int BannerTypeId)
		{
			string _DisplayType = Null.NullString;
			try {
				switch (BannerTypeId) {
					case (int)Services.Vendors.BannerType.Banner:
						_DisplayType = Services.Localization.Localization.GetString("BannerType.Banner.String", Services.Localization.Localization.GlobalResourceFile);
						break;
					case (int)Services.Vendors.BannerType.MicroButton:
						_DisplayType = Services.Localization.Localization.GetString("BannerType.MicroButton.String", Services.Localization.Localization.GlobalResourceFile);
						break;
					case (int)Services.Vendors.BannerType.Button:
						_DisplayType = Services.Localization.Localization.GetString("BannerType.Button.String", Services.Localization.Localization.GlobalResourceFile);
						break;
					case (int)Services.Vendors.BannerType.Block:
						_DisplayType = Services.Localization.Localization.GetString("BannerType.Block.String", Services.Localization.Localization.GlobalResourceFile);
						break;
					case (int)Services.Vendors.BannerType.Skyscraper:
						_DisplayType = Services.Localization.Localization.GetString("BannerType.Skyscraper.String", Services.Localization.Localization.GlobalResourceFile);
						break;
					case (int)Services.Vendors.BannerType.Text:
						_DisplayType = Services.Localization.Localization.GetString("BannerType.Text.String", Services.Localization.Localization.GlobalResourceFile);
						break;
					case (int)Services.Vendors.BannerType.Script:
						_DisplayType = Services.Localization.Localization.GetString("BannerType.Script.String", Services.Localization.Localization.GlobalResourceFile);
						break;
				}
			} catch (Exception exc) {
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
			return _DisplayType;
		}
		public string FormatURL(string strKeyName, string strKeyValue)
		{
			return EditUrl(strKeyName, strKeyValue, "Banner", "VendorId=" + VendorID.ToString());
		}
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);
			try {
				if (!Null.IsNull(VendorID)) {
					BindData();
				} else {
					this.Visible = false;
				}
			} catch (Exception exc) {
				Services.Exceptions.Exceptions.ProcessModuleLoadException(this, exc);
			}
		}
		public ModuleActionCollection ModuleActions {
			get {
				ModuleActionCollection Actions = new ModuleActionCollection();
				if ((Request.QueryString["VendorID"] != null)) {
					VendorID = Int32.Parse(Request.QueryString["VendorID"]);
				} else {
					VendorID = Null.NullInteger;
				}
				Actions.Add(GetNextActionID(), Services.Localization.Localization.GetString(ModuleActionType.AddContent, LocalResourceFile), ModuleActionType.AddContent, "", "", EditUrl("VendorID", VendorID.ToString(), "Banner"), false, SecurityAccessLevel.Admin, Null.IsNull(VendorID) == false, false);
				return Actions;
			}
		}
	}
}
